<template>
  <div class="rich-text-display" v-html="formattedContent"></div>
</template>

<script>
export default {
  name: 'RichTextDisplay',
  props: {
    content: {
      type: String,
      default: ''
    },
    className: {
      type: String,
      default: ''
    }
  },
  computed: {
    formattedContent() {
      if (!this.content) return '';
      
      // 如果内容已经是HTML格式，直接返回
      if (this.content.includes('<') && this.content.includes('>')) {
        return this.content;
      }
      
      // 如果是纯文本，进行基本的格式化
      return this.content
        .replace(/\n/g, '<br>')
        .replace(/\s{2,}/g, '&nbsp;&nbsp;');
    }
  }
}
</script>

<style scoped>
.rich-text-display {
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.rich-text-display :deep(img) {
  max-width: 100%;
  height: auto;
  margin: 8px 0;
}

.rich-text-display :deep(p) {
  margin: 8px 0;
}

.rich-text-display :deep(h1),
.rich-text-display :deep(h2),
.rich-text-display :deep(h3),
.rich-text-display :deep(h4),
.rich-text-display :deep(h5),
.rich-text-display :deep(h6) {
  margin: 12px 0 8px 0;
  font-weight: 600;
}

.rich-text-display :deep(ul),
.rich-text-display :deep(ol) {
  margin: 8px 0;
  padding-left: 20px;
}

.rich-text-display :deep(li) {
  margin: 4px 0;
}

.rich-text-display :deep(blockquote) {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 4px solid #e4e7ed;
  background-color: #f9f9f9;
  color: #606266;
}

.rich-text-display :deep(code) {
  background-color: #f5f5f5;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.rich-text-display :deep(pre) {
  background-color: #f5f5f5;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
}

.rich-text-display :deep(pre code) {
  background-color: transparent;
  padding: 0;
}

.rich-text-display :deep(a) {
  color: #409eff;
  text-decoration: none;
}

.rich-text-display :deep(a:hover) {
  text-decoration: underline;
}

.rich-text-display :deep(table) {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}

.rich-text-display :deep(th),
.rich-text-display :deep(td) {
  border: 1px solid #e4e7ed;
  padding: 8px;
  text-align: left;
}

.rich-text-display :deep(th) {
  background-color: #f5f7fa;
  font-weight: 600;
}
</style> 